package cn.edu.zut.curriculum.service.impl;

import cn.edu.zut.curriculum.entity.Commodity;
import cn.edu.zut.curriculum.mapper.CommodityMapper;
import cn.edu.zut.curriculum.service.ICommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityServiceimpl implements ICommodityService {
    @Autowired
    CommodityMapper commodityMapper;

    @Override
    public List<Commodity> select(String name) {
        if (commodityMapper.queryByName(name) != null) {
            List<Commodity> list = commodityMapper.queryByName(name);
            return list;
        } else
            return null;

    }

    @Override
    public Commodity insert(Commodity commodity) {
        if (commodityMapper.insertCommodity(commodity) == 1) {
            return commodity;
        } else {
            commodity.setMessage("未知错误，请重试");
            return commodity;
        }
    }

    @Override//  搜索商品
    public Commodity select(long id) {
        Commodity commodity = commodityMapper.queryById(id);
        return commodity;
    }
    @Override// 所有闲置物品的查询
    public Commodity select2(long id) {
        Commodity commodity = commodityMapper.queryById2(id);
        return commodity;
    }

    @Override//  搜索商品
    public List<Commodity> select5(long id) {
       List<Commodity>  list = commodityMapper.queryById5(id);
        return list;

    }



    @Override
    public int update(long id){
       int i=commodityMapper.updateById(id);
        return i;
    }

    @Override
    public int update2(long id) {
        int i=commodityMapper.updateById2(id);
        return i;
    }


    @Override
    public int update3(String price,long id){
        int i=commodityMapper.updateById3(price,id);
        return i;
    }

    @Override
    public List<Commodity> select3(long uid){
        List<Commodity>list=commodityMapper.queryById3(uid);
        return list;
    }

    @Override
    public int delete(long id){
        int i=commodityMapper.delete(id);
        return i;
    }

}